<template>
  <el-select placeholder="请选择仓库" clearable v-model="selections">
    <el-option
      v-for="warehouse in options"
      :key="warehouse.id"
      :label="warehouse.label"
      :value="warehouse.id"
    ></el-option>
  </el-select>
</template>

<script>
import { mapGetters } from "vuex";
import Treeselect from "@riophae/vue-treeselect";
export default {
  components: { Treeselect },
  props: {
    value: {
      type: [String, Number, Array],
      default: null,
    },
    size: {
      type: String,
      default: "small",
    },
    disabled: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      options: [],
    };
  },
  computed: {
    ...mapGetters(["rackList", "areaList", "warehouseList"]),
    selections: {
      get() {
        return this.value;
      },
      set(v) {
        this.$emit("input", v);
      },
    },
  },
  created() {
    this.setOptions();
  },
  methods: {
    feiSelect(node) {
      // 触发自定义事件，并传递选中项的id和name
      this.$emit("wareHouseSelect", { id: node.id, name: node.label });
    },
    setOptions() {
      this.options = this.warehouseList.map((warehouse) => {
        return {
          id: warehouse.id,
          label: warehouse.warehouseName,
        };
      });
    },
  },
};
</script>
